package com.lanou.service.imp;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lanou.bean.Account;
import com.lanou.bean.AdminInfo;
import com.lanou.mapper.AccountMapper;
import com.lanou.mapper.ServiceMapper;
import com.lanou.service.AccountService;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * Created by dllo on 18/3/13.
 */
@Service
public class AccountServiceImpl implements AccountService {
    @Resource
    private AccountMapper accountMapper;
    @Resource
    private ServiceMapper serviceMapper;
    @Override
    public List<Account> findAccountAll() {
        return accountMapper.findAccountAll();
    }

    @Override
    public PageInfo<Account> queryAccountByPage(Integer pageNo, Integer pageSize) {
        pageNo = pageNo == null?1:pageNo;
        pageSize = pageSize == null?3:pageSize;
        PageHelper.startPage(pageNo,pageSize);
        List<Account> accountList = accountMapper.findAccountAll();
        PageInfo<Account> accountPageInfo = new PageInfo<Account>(accountList);
        System.out.println(accountPageInfo);
        return accountPageInfo;
    }

    @Override
    public void accountAdd(String realName, String idcardNo, String loginName, String loginPasswd, String telephone, Date createDate) {
        accountMapper.accountAdd(realName,idcardNo,loginName,loginPasswd,telephone,createDate,0);
    }

    @Override
    public void accountUpdate(@Param("realName") String realName, @Param("telephone") String telephone, @Param("email") String email,@Param("gender") String gender, @Param("zipcode") String zipcode, @Param("qq") String qq, @Param("accountId") Integer accountId) {
        accountMapper.accountUpdate(realName,telephone,email,gender,zipcode,qq,accountId);
    }

    @Override
    public List<Account> findAccountById(Integer accountId) {
        return accountMapper.findAccountById(accountId);
    }

    @Override
    public void deleteAccountAndService(Integer accountId) {
        accountMapper.accountDelete(accountId);
        serviceMapper.serviceDeleteByAccountId(accountId);
    }

    @Override
    public void updateStatusById(@Param("status") String status,@Param("accountId") Integer accountId) {
        accountMapper.updateStatusById(status,accountId);
    }

    @Override
    public Account idcardNologinNameisexist(@Param("idcardNo") String idcardNo, @Param("loginName") String loginName) {
        return accountMapper.idcardNologinNameisexist(idcardNo,loginName);
    }


}
